June 9, 2015

Cost of an Education?

Cost of an Education!

  • … some charts are easier to read.
  • we will be talking about why

Good Graphics

Graphics consist of

  • Structure (boxplot, scatterplot, etc.)
  • Aesthetics: features such as color, shape, and size that map other characteristics to structural features

Both the structure and aesthetics should help viewers interpret the information.

Outline

  • Cognitive aspects of perception and aesthetic choices
  • Visual ordering mechanisms and color choices
  • Faceting graphs to show additional variables

Pre-Attentive Features

  • pre-attentive: things that "jump out" in less than 250 ms (less than the time for a blink of an eye)
  • Color, form, movement, spatial localization

Can you spot the odd one out?

     

nice applet by Chris Healey

Hierarchy of Features

  • Color is stronger than shape

  • Combination of pre-attentive features is usually not pre-attentive due to interference.

Can you spot the odd one out?

     

'Features' in ggplot2

  • Features in ggplot2 are called aesthetics

  • main ones: colour, size, shape, alpha value

  • … let's play with them a bit …

Your Turn

Find ways to improve the following graphic:

  • Make sure the "oddball" stands out while keeping the information on the groups
  • Hint: interaction combines factor variables
frame <- data.frame(x=runif(25), y=runif(25),
  g1=rep(c("A","B"), c(12,13)),
    g2=rep(c("1", "2"), c(13,12)))
qplot(x,y, shape=g1, colour=g2, data=frame, size=I(4))

Color

  • Hue: shade of color (red, orange, yellow…)
  • Intensity: amount of color
  • Both color and hue are pre-attentive. Bigger contrast corresponds to faster detection.

Color is context-sensitive

The exact same hue and intensity in one situation may appear to be a different color in a different context.

A and B are the same intensity and hue, but appear to be different.

Data Quantities

Which is bigger?

  • Position: higher is bigger (y), items to the right are bigger (x)
  • Size, Area
  • Color: not always ordered. More contrast = bigger.
  • Shape: Unordered.

           

Aesthetics in ggplot2

Using Color

  • Qualitative schemes: (not a lot more than 7 colors)

Quantitative schemes:

  • use color gradient with only one hue for positive values

  • use color gradient with two hues for positive and negative values. Gradient should go through a light, neutral color (white)
  • Small objects or thin lines need more contrast than larger areas

RColorBrewer

R package based on Cynthia Brewer's color schemes ColorBrewer2.org

install.packages("RColorBrewer")
library(RColorBrewer)
help(package=RColorBrewer)
display.brewer.all()

Color in ggplot2

  • factor variable: scale_colour_discrete, scale_colour_brewer(palette=...)

  • continuous variable:

scale_colour_gradient (define low, high values)

scale_colour_gradient2 (define low, mid, and high values)

  • equivalent scales for scale_fill_XXX

Your Turn

  • In the diamonds data, clarity and cut are ordinal, while price and carat are continuous
  • Find a graphic that gives an overview of these four variables while respecting their types
data(diamonds)
qplot(carat, price, shape=cut, colour=clarity,
      data=diamonds)

Facetting

  • A way to extract subsets of data and place them side-by-side in graphics
  • Syntax: facets = row ~ col Use . if there is no variable for either row or column (i.e. facets = . ~ col)
qplot(price, carat, data=diamonds, color=color,
      facets = . ~ clarity)

Your Turn

  • The movies dataset contains information from IMDB.com including ratings, genre, length in minutes, and year of release.

  • Explore the differences in length, rating, etc. in movie genres over time

  • Hint: use facetting!